{% comment %}
#    Copyright 2012 New Mexico EPSCoR
#
#    This file is part of Teacher's P.E.T.
#
#    Teacher's P.E.T. is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    Teacher's P.E.T. is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with Teacher's P.E.T..  If not, see <http://www.gnu.org/licenses/>.
{% endcomment %}
<style type="text/css">
    .management-forum-ban-table td
    {
        vertical-align: middle;
    }
</style>
<h1>
    Forum
    {% if Forum %}<a class="button DeleteButton floatright" href="{% course_url management app='forum' command='delete' %}" title="Delete this forum">X</a>{% endif %}
</h1>
<br>
{% if Forum %}
        <form action="." method="post">{% csrf_token %}
    <table border="0" class="indent" cellspacing=0 cellpadding=0>
    {% if TaggedEntries %}
    {% regroup TaggedEntries by flagged_as_deleted as TaggedEntries %}
        {% for group in TaggedEntries %}
            {% if not group.grouper %}
                <tr><th colspan="100%" style="text-align: left;"><h2>Posts Flagged for Moderation</h2>The following forum posts have been flagged for inappropriate content<br>&nbsp;</th></tr>
            {% else %}
                <tr><th colspan="100%" style="text-align: left;"><h2>Posts Deleted</h2>The following forum posts have been hidden from users in the forum<br>&nbsp;</th></tr>
            {% endif %}
        <tr><th class="border-bottom">Author</th><th colspan="3" class="border-bottom">Thread</th><th colspan="4" class="border-bottom">Post</th><th class="border-bottom" colspan="100%">Options</th></tr>
        {% for entry in group.list %}
            <tr>
                <td>{{entry.author.user.last_name}}, {{entry.author.user.first_name}} ({{entry.author.user.username}})</td>
                <td colspan="3">{{entry.thread.title|spacify}}</td>
                <td colspan="4"><a href="{% course_url forum_view_entries thread_id=entry.thread.id %}?post={{entry.entry_number}}#post{{entry.entry_number}}" target="_blank">{{entry.entry|strip_html|slice:":150"}}</a></td>
                <td class="management_option">
                {% if not group.grouper %}
                <a class="button smallbutton" href="{% course_url management app='forum' command='alter_entry' arguments=entry.id|concat:'&unflag'%}" title="Unflag this post as requiring moderation">Unflag</a>
                <a class="button smallbutton" href="{% course_url management app='forum' command='alter_entry' arguments=entry.id|concat:'&hide'%}" title="Mark this post as hidden. Will only be viewable here">Hide</a>
                {% else %}
                <a class="button smallbutton" href="{% course_url management app='forum' command='alter_entry' arguments=entry.id|concat:'&unhide'%}" title="Make this post visible to all users again">Unhide</a>
                {% endif %}
                <a class="button smallbutton" href="{% course_url management app='forum' command='ban' arguments=entry.author.id %}" title="Place restrictions on this user's forum and message activity">Ban</a>
                <a class="button smallbutton" href="{% course_url forum_view_entries thread_id=entry.thread.id %}?post={{entry.entry_number}}#post{{entry.entry_number}}" target="_blank" title="View this post">View</a>
                </td>
            </tr>
        {% endfor %}
        {% endfor %}
    {% endif %}

    {% if TaggedThreads %}
        <tr><th colspan="100%" style="text-align: left;"><h2>Threads Marked as Deleted</h2>The following threads have been hidden from users in the forum<br>&nbsp;</th></tr>
        <tr><th class="border-bottom">Author</th><th colspan="7" class="border-bottom">Thread</th><th class="border-bottom" colspan="100%">Options</th></tr>
        {% for thread in TaggedThreads %}
            <tr>
                <td>{{thread.first_entry.author.user.last_name}}, {{thread.first_entry.author.user.first_name}} ({{thread.first_entry.author.user.username}})</td>
                <td colspan="7">{{thread.title|spacify}}</td>
                <td class="management_option">
                <a class="button smallbutton" href="{% course_url management app='forum' command='alter_thread' arguments=thread.id|concat:'&unhide&management'%}" title="Make this post visible to all users again">Unhide</a>
                <a class="button smallbutton" href="{% course_url management app='forum' command='ban' arguments=thread.first_entry.author.id %}" title="Place restrictions on this user's forum and message activity">Ban</a>
                <a class="button smallbutton" href="{% course_url forum_view_entries thread_id=thread.id %}" target="_blank" title="View this thread">View</a>
                </td>
            </tr>
        {% endfor %}
    {% endif %}
    
    {% if TaggedMessages %}
        <tr><th colspan="100%" style="text-align: left;"><h2>Messages Flagged for Moderation</h2>The following messages have been flagged for inappropriate content<br>&nbsp;</th></tr>
        <tr><th class="border-bottom">Author</th><th class="border-bottom">Recipient</th><th colspan="2" class="border-bottom">Subject</th><th colspan="4" class="border-bottom">Message</th><th class="border-bottom" colspan="100%">Options</th></tr>
        {% for msg in TaggedMessages %}
            <tr>
                <td>{{msg.sender_name}} ({{msg.sender.username}})</td>
                <td>{{msg.recipient_name}} ({{msg.recipient.username}})</td>
                <td colspan="2">{{msg.subject}}</td>
                <td colspan="4"><a href="{% course_url forum_view_message message_id=msg.id %}" target="_blank">{{msg.message|strip_html}}</a></td>
                <td class="management_option">
                <a class="button smallbutton" href="{% course_url management app='forum' command='alter_message' arguments=msg.id|concat:'&unflag'%}" title="Unflag this message as requiring moderation">Unflag</a>
                {% if not msg.is_hidden %}
                    <a class="button smallbutton" href="{% course_url management app='forum' command='alter_message' arguments=msg.id|concat:'&hide'%}" title="Hide this message so students cannot see it (it is still accessible here)">Hide</a>
                {% else %}
                    <a class="button smallbutton" href="{% course_url management app='forum' command='alter_message' arguments=msg.id|concat:'&unhide'%}" title="Unhide this message so students can see it again">Unhide</a>
                {% endif %}
                <a class="button smallbutton" href="{% course_url management app='forum' command='ban' arguments=msg.sender.course_participant.id %}" title="Place restrictions on this user's forum and message activity">Ban</a>
                <a class="button smallbutton" href="{% course_url forum_view_message message_id=msg.id %}" target="_blank" title="View this message">View</a>
                </td>
            </tr>
        {% endfor %}
    {% endif %}

    {% if Bans %}
                <tr><th colspan="100%" style="text-align: left;"><h2>Restrictions</h2>Users who have or have ever had restrictions placed upon them are listed here<br>&nbsp;</th></tr>
                <tr>
                    <th></th>
                    <th class="border-top border-left border-right" colspan="3">Forum Permissions</th>
                    <th class="border-top border-left border-right" colspan="4">Messaging Permissions</th>
                </tr>
                <tr>
                    <th class="border-bottom">User</th>
                    <th class="border-bottom border-left">Attach Files</th>
                    <th class="border-bottom">Create/Edit Posts</th>
                    <th class="border-bottom border-right">View Posts</th>
                    <th class="border-bottom border-left">Attach Files</th>
                    <th class="border-bottom">New Messages</th>
                    <th class="border-bottom">Reply to Messages</th>
                    <th class="border-bottom border-right">View Messages</th>
                    <th class="border-bottom">Options</th>
                </tr>
                {% for ban in Bans %}
                    <tr>
                        <td>{{ban.course_participant.user.last_name}}, {{ban.course_participant.user.first_name}} ({{ban.course_participant.user.username}})</td>
                        <td>{% if ban.forum_ban >= ban.BAN_POST_ATTACHMENTS %}<img src="{{STATIC_URL}}images/x.png" height="16">{% else %}<img src="{{STATIC_URL}}images/check.png" height="16">{%endif%}</td>
                        <td>{% if ban.forum_ban >= ban.BAN_POSTS %}<img src="{{STATIC_URL}}images/x.png" height="16">{% else %}<img src="{{STATIC_URL}}images/check.png" height="16">{%endif%}</td>
                        <td>{% if ban.forum_ban >= ban.BAN_FORUM %}<img src="{{STATIC_URL}}images/x.png" height="16">{% else %}<img src="{{STATIC_URL}}images/check.png" height="16">{%endif%}</td>
                        <td>{% if ban.message_ban >= ban.BAN_MESSAGE_ATTACHMENTS %}<img src="{{STATIC_URL}}images/x.png" height="16">{% else %}<img src="{{STATIC_URL}}images/check.png" height="16">{%endif%}</td>
                        <td>{% if ban.message_ban >= ban.BAN_NEW_MESSAGES %}<img src="{{STATIC_URL}}images/x.png" height="16">{% else %}<img src="{{STATIC_URL}}images/check.png" height="16">{%endif%}</td>
                        <td>{% if ban.message_ban >= ban.BAN_REPLIES %}<img src="{{STATIC_URL}}images/x.png" height="16">{% else %}<img src="{{STATIC_URL}}images/check.png" height="16">{%endif%}</td>
                        <td>{% if ban.message_ban >= ban.BAN_MESSAGES %}<img src="{{STATIC_URL}}images/x.png" height="16">{% else %}<img src="{{STATIC_URL}}images/check.png" height="16">{%endif%}</td>
                        <td class="management_option">
                            <a class="button smallbutton" href="{% course_url management app='forum' command='ban' arguments=ban.course_participant.id %}" title="Makes changes to the restrictions placed upon this user">Update Restrictions</a>
                        </td>
                    </tr>
                {% endfor %}
    {% endif %}
    
    {% if BlockList %}
        <tr><th colspan="100%" style="text-align: left;"><h2>Blocked Users</h2>Users who have been blocked by other users are displayed here<br>&nbsp;</th></tr>
        <tr><th class="border-bottom">Blocked User</th><th colspan="7" class="border-bottom">Users Who Blocked This User</th><th class="border-bottom">Options</th></tr>
        {% for cp,blocks in BlockList %}
            {% if blocks|length > 0 %}
                <tr>
                    <td>{{cp.user.last_name}},&nbsp;{{cp.user.first_name}}&nbsp;({{cp.user.username}})</td>
                    <td colspan="7">{{blocks|length}}</td>
                    <td>
                        <a class="button smallbutton" href="{% course_url management app='forum' command='ban' arguments=cp.id %}" title="Place restrictions on this user's forum and message activity">Ban</a>        
                        <a class="button smallbutton" href="{% course_url management app='forum' command='view_messages' arguments=cp.user.username %}" title="View the messages this user has sent">View</a>        
                    </td>
                </tr>
            {% endif %}
        {% endfor %}
    {% endif %}
    </table>
        </form>

    <form action="{% course_url management app='forum' command='delete' %}" method="POST">{% csrf_token %}
    <a class="button smallbutton" href="{% course_url forum_view_threads %}">Go to Forum</a>
        <button type="submit" class="button smallbutton" title="Remove forum from this course (requires confirmation).">Remove Forum</button>
    </form>
{% else %}
    <p>No forum exists for this course. You can either create one or attach another course's forum (that will be shared between courses)</p>
    <form action="{% course_url management app='forum' command='create' %}" method="POST">{% csrf_token %}
        <h2>Create Forum</h2>
        <label for="title">Course Forum Title:</label><input type="text" name="title" id="title" value="{{course.course_title}}"></input>
        <button type="submit" class="button SaveButton">Create</button>
    </form>
    <form action="{% course_url management app='forum' command='attach' %}" method="POST">{% csrf_token %}
        <h2>Attach Forum</h2>
        {{AttachForm}}
        <button type="submit" class="button SaveButton">Create</button>
    </form>
{% endif %}

